<style lang="less">
@import "./Product.less";
</style>

<template>
  <div
    :class="{ 'product1-container': true, 'product1-large': size == 'large' }"
    :style="styleObject"
  >
    <div @click="clickProduct" style="cursor: pointer">
      <div
        :class="{
          'card-top': type != 'bounce',
          'card-top bounce': type == 'bounce',
        }"
      >
        <Badge :text="data.tag" :class-name="bageClass">
          <img class="img-up" v-lazy="data.picUrl" />
        </Badge>
        <div v-if="data.label" class="product-label">
          <span>{{ data.label }}</span>
        </div>
        <div v-if="type == 'bounce'">
          <img class="img-mid" v-lazy="data.picUrl" />
          <img class="img-down" v-lazy="data.picUrl" />
        </div>
      </div>
      <div class="card-content">
        <div class="name" :style="styleObject">{{ data.title }}</div>
        <div class="comment" v-if="size == 'large' && showRate">
          <div>销量：{{ data.sales }}</div>
          <div>评价：{{ data.rate }} 分</div>
        </div>
        <div class="info">
          {{ data.description }}
        </div>
        <div class="price" v-if="showPrice">
          <span class="p" :style="{ color: color }"
            >￥{{ Number(data.price).toFixed(2) }}</span
          >
          <span v-if="size != 'large'" class="sales"
            >销量：{{ data.sales }}</span
          >
          <div v-if="size == 'large'" class="add-cart" @click="clickCart">
            <a><Icon type="md-cart"></Icon>加入购物车</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ProductMooc",
  data() {
    return {};
  },
  props: {
    data: {
      type: Object,
      default: function () {
        return {
          sales: 0,
        };
      },
    },
    color: {
      type: String,
      default: "#F01414",
    },
    type: {
      type: String,
      default: "",
    },
    size: {
      type: String,
      default: "",
    },
    showPrice: {
      type: Boolean,
      default: true,
    },
    showRate: {
      type: Boolean,
      default: true,
    },
  },
  computed: {
    bageClass() {
      let tag = String(this.data.tag).toLowerCase();
      if (tag == "new" || tag == "hot") {
        return tag;
      } else {
        return "bage";
      }
    },
    styleObject: function () {
      return {
        "--color": this.color,
      };
    },
  },
  methods: {
    clickProduct() {
      this.$emit("on-click", this.data);
    },
    clickCart() {
      this.$emit("on-click-cart", this.data);
    },
  },
  mounted() {},
};
</script>
